/**
 *
 */
package jp.seraph.same.view.cui;

import jp.seraph.cui.AbstractData;
import jp.seraph.cui.Data;
import jp.seraph.cui.InternalConsole;
import jp.seraph.cui.Mode;
import jp.seraph.cui.SystemNode;
import jp.seraph.cui.SystemNodeType;
import jp.seraph.jsade.math.Angle;
import jp.seraph.jsade.model.JointIdentifier;
import jp.seraph.jsade.model.JointIdentifierContainer;
import jp.seraph.same.controller.PoseController;
import jp.seraph.same.model.PoseModel;

/**
 *
 *
 */
public class PoseData extends AbstractData implements SystemNode, Data {
    public PoseData(String aPoseName, PoseModel aModel, PoseController aController, Mode aParent, InternalConsole aConsole, JointIdentifierContainer aIdContainer){
        super(aParent, aConsole);

        mName = aPoseName;
        mIdContainer = aIdContainer;
        mModel = aModel;
        mController = aController;
    }

    private String mName;
    private PoseModel mModel;
    private JointIdentifierContainer mIdContainer;
    private PoseController mController;

    /**
     *
     * @see jp.seraph.cui.SystemNode#getName()
     */
    public String getName() {
        return mName;
    }

    /**
     *
     * @see jp.seraph.cui.SystemNode#setName(java.lang.String)
     */
    public void setName(String aName) {
        mName = aName;
    }

    /**
     *
     * @see jp.seraph.cui.SystemNode#getType()
     */
    public SystemNodeType getType() {
        return PoseDataType.getInstance();
    }

    /**
     *
     * @see jp.seraph.cui.Data#getData()
     */
    public String getData() {
        StringBuilder tBuilder = new StringBuilder();
        for (JointIdentifier tId : mIdContainer) {
            tBuilder.append(tId.toJointName()).append(" : ").append(mModel.getAngle(tId).getDegree());
            tBuilder.append(System.getProperty("line.separator"));
        }

        return tBuilder.toString();
    }

    /**
     *
     * @see jp.seraph.cui.SystemNode#isRoot()
     */
    public boolean isRoot() {
        return false;
    }

    public PoseModel getPoseModel(){
        return mModel;
    }

    public void setAngle(JointIdentifier aId, Angle aAngle){
        mController.setAngle(aId, aAngle);
    }

    /**
     *
     * @see jp.seraph.cui.AbstractNode#delete()
     */
    @Override
    public void delete() {
        super.delete();
        mController.delete();
    }
}
